package cn.gx.kevin.common.ui;

import cn.gx.kevin.common.tree.IListToTree;
import cn.gx.kevin.common.tree.ListToTree;
import cn.gx.kevin.controller.ResetfulBaseController;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class TreeTools <E>{

    IListToTree toTree;
    public TreeTools(IListToTree<E> listToTree){
        toTree = listToTree;
    }

    /**
     * @throws Throwable
     * 用于列表转树形 需要子类，重写实现 createTreeNode 、getTreeNodeId、getTreeNodeText
     *               getTreeNodePid isTreeNodeLeaf createTreeNodeButton
     * @param list
     */
    @SuppressWarnings("unchecked")
    public <E> JSONArray listToTreeJson(List<E> list, String pid) throws Throwable {
        return this.listToTreeJson(list, pid, null);
    }

    /**
     * 用于列表转树形 需要子类，重写实现 createTreeNode 、getTreeNodeId、getTreeNodeText
     *                      getTreeNodePid isTreeNodeLeaf
     *                      createTreeNodeButton @param list @param extParams
     *                      转换过程总需要用到的参数
     */
    @SuppressWarnings("unchecked")
    public  <E> JSONArray listToTreeJson(List<E> list, String pid, Object extParams) throws Throwable {
        ListToTree<E> toTree = new ListToTree<E>(new ArrayList<ClientButton>(),this.toTree);
        return toTree.getJSONArray(pid, list, extParams);
    }


}
